package com.qf.android.huihui.view.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.qf.android.huihui.R;
import com.qf.android.huihui.adapter.information.InformationAdapter;
import com.qf.android.huihui.bean.InformationBean;
import com.qf.android.huihui.common.InfoRecyclerView;
import com.qf.android.huihui.presenter.InformationPresenter;
import com.qf.android.huihui.view.fragment.impl.BaseFragment;
import com.qf.android.huihui.view.fragment.impl.IShowView;

/**
 * A simple {@link Fragment} subclass.
 */
public class InformationFragment extends BaseFragment implements IShowView,PullToRefreshBase.OnRefreshListener2 {
     private InfoRecyclerView infoRecyclerView;
     private InformationPresenter presenter;
     private InformationAdapter adapter;
     public InformationFragment() {
        // Required empty public constructor
     }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_infomation, container, false);
        infoRecyclerView= (InfoRecyclerView) view.findViewById(R.id.fragment_info_recycleview);
        infoRecyclerView.setMode(PullToRefreshBase.Mode.BOTH);
        LinearLayoutManager manager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        infoRecyclerView.getRefreshableView().setLayoutManager(manager);
        infoRecyclerView.setOnRefreshListener(this);
        presenter=new InformationPresenter(this);
        presenter.getData(0,0,false,false,null,null);
        return view;
    }
    @Override
    public void setData(Object data) {
        InformationBean informationBean= (InformationBean) data;
         adapter=new InformationAdapter(informationBean,getContext());
         infoRecyclerView.getRefreshableView().setAdapter(adapter);
    }
    @Override
    public void onClick(View v) {

    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase refreshView) {
        presenter.getData(0,0,false,true,adapter,infoRecyclerView);
    }
    @Override
    public void onPullUpToRefresh(PullToRefreshBase refreshView) {
        presenter.getData(0,0,true,false,adapter,infoRecyclerView);
    }
}
